package com.sdkx.app.datalayers;

import java.util.concurrent.LinkedBlockingDeque;

import cn.creable.gridgis.geometry.IEnvelope;

public class LayersUpdateThread extends Thread {
    IEnvelope iEnvelope;
    LinkedBlockingDeque<Runnable> linkedBlockingDeque = new LinkedBlockingDeque<>();

    @Override
    public void run() {
        while (true) {
            try {
                Runnable runnable = linkedBlockingDeque.take();
                runnable.run();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void putTask(Runnable runnable) {
        linkedBlockingDeque.add(runnable);
    }

    public IEnvelope getiEnvelope() {
        return iEnvelope;
    }

    public boolean isEnvChanaged(IEnvelope iEnv) {
        if(iEnvelope == null){
            iEnvelope = iEnv;
            return true;
        }
        boolean xmax = iEnvelope.getXMax() == iEnv.getXMax();
        boolean xMin = iEnvelope.getXMin() == iEnv.getXMin();
        boolean yMax = iEnvelope.getYMax() == iEnv.getYMax();
        boolean yMin = iEnvelope.getYMin() == iEnv.getYMin();
        return !(xmax && xMin && yMax && yMin);
    }

    public void setiEnvelope(IEnvelope iEnvelope) {
        this.iEnvelope = iEnvelope;
    }
}
